package ir.values.users.instructions.jump;

import ir.types.datatypes.VoidType;
import ir.values.Value;
import ir.values.users.instructions.InstOperator;
import ir.values.users.instructions.Instruction;

public class RetInst extends JumpInst {
    private final Value returnedValue;
    public RetInst(Value returnedValue) {
        super(VoidType.VOID);
        this.returnedValue = returnedValue;
        this.operands.add(returnedValue);
    }
    @Override
    public boolean shouldGenerateId() {
        return false;
    }
    @Override
    public InstOperator getInstOperator() {
        return InstOperator.ret;
    }

    @Override
    public String parseLLVM() {
        // eg: ret i32 0
        StringBuilder sb = new StringBuilder();
        sb
                .append(getInstOperator())
                .append(" ")
                .append(returnedValue.getType().toString());
        if (!(returnedValue.getType() instanceof VoidType)) {
            sb
                    .append(" ")
                    .append(returnedValue.parseUsingName());
        }
        return sb.toString();
    }
}
